#include <header.h>
#include <iostream>

int main()
{
    int clientfd = socket(AF_INET, SOCK_STREAM, 0);
    if(clientfd < 0) {
        perror("socket");
        return EXIT_FAILURE;
    }

    struct sockaddr_in serveraddr;
    memset(&serveraddr, 0, sizeof(serveraddr));
    serveraddr.sin_family = AF_INET;
    serveraddr.sin_port = htons(8000);
    //serveraddr.sin_addr.s_addr = inet_addr("192.168.30.129");
    serveraddr.sin_addr.s_addr = inet_addr("127.0.0.1");//代表本机地址

    int ret = connect(clientfd, (const struct sockaddr*)&serveraddr, sizeof(serveraddr));
    if(ret < 0) {
        perror("connect");
        close(clientfd);
        return EXIT_FAILURE;
    }

    printf("connect success\n");

#if 0
    //指定用户态接收缓冲区
    char buff[1024] = {0};
    //当第三个参数对数组使用sizeof运算符时，
    //表示最大可以接收数组的空间的数据量
    ret = recv(clientfd, buff, sizeof(buff), 0);
    printf("recv %d bytes.\n", ret);
    printf("buff: %s\n", buff);

    const char * msg = "hello, server";
    ret = send(clientfd, msg, strlen(msg), 0);
    printf("send %d bytes.\n", ret);
#endif
    while(1);

    close(clientfd);
    return 0;
}


